/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tutorial.BuilderSiDAO;

import tutorial.BuilderSiDAO.BuilderPattern.SwingExporter;
import tutorial.BuilderSiDAO.BuilderPattern.SwingImporter;
import tutorial.BuilderSiDAO.DAOPattern.SwingPersoanaDAO;
import tutorial.BuilderSiDAO.commons.ptBuilderPersoana;
import tutorial.BuilderSiDAO.commons.ptBuilderPersoana.Exporter;
import tutorial.BuilderSiDAO.commons.ptBuilderPersoana.Importer;
import tutorial.BuilderSiDAO.commons.ptDAOPersoana;
import tutorial.BuilderSiDAO.commons.ptDAOPersoana.PersoanaDAO;

/**
 * Aici este un exemplu alea implementarului SwingImporter si SwingExporter
 * si SwingPersoanaDAO
 * @author Boogie
 */
public class TutorialCuGUI extends javax.swing.JFrame {

    
    public TutorialCuGUI() {
        initComponents();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        persoanaGUIinputCuBuiller = new tutorial.BuilderSiDAO.customGUI.PersoanaGUIInput();
        persoanaGUIoutputCuBuilder = new tutorial.BuilderSiDAO.customGUI.PersoanaGUIOutput();
        addCuBuilder = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        persoanaGUIImputCuDAO = new tutorial.BuilderSiDAO.customGUI.PersoanaGUIInput();
        persoanaGUIoutputCuDAO = new tutorial.BuilderSiDAO.customGUI.PersoanaGUIOutput();
        addCuDAO = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Cu Builder"));

        addCuBuilder.setText("Add Cu Builder");
        addCuBuilder.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addCuBuilderActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(addCuBuilder, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(persoanaGUIinputCuBuiller, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())
                    .addComponent(persoanaGUIoutputCuBuilder, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(persoanaGUIinputCuBuiller, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(persoanaGUIoutputCuBuilder, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(addCuBuilder)
                .addContainerGap())
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Cu DAO"));

        addCuDAO.setText("Add Cu DAO");
        addCuDAO.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addCuDAOActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(persoanaGUIoutputCuDAO, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(persoanaGUIImputCuDAO, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(addCuDAO, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(persoanaGUIImputCuDAO, javax.swing.GroupLayout.DEFAULT_SIZE, 195, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(persoanaGUIoutputCuDAO, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(addCuDAO)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    
    
    
    //Buton Cu Builder
    private void addCuBuilderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addCuBuilderActionPerformed
        Importer importer = new SwingImporter(this.persoanaGUIinputCuBuiller);
        ptBuilderPersoana p = new ptBuilderPersoana(importer);
        Exporter exporter = new SwingExporter(persoanaGUIoutputCuBuilder);
        //aici pot fara probleme sa adaug un exporter(builder) pentru altceva
        /*
         * Exporter exporter = new StdExporter();
         * p.export(exporter);
         * 
         * si va merge deoarece obiectul Persoana nu stie nimic despre implenetarea exporterului
         * 
         * la fel si pentru importer
         * vazi clasa  TutorialCombinat pentru detalii
         */
        p.export(exporter);
        
    }//GEN-LAST:event_addCuBuilderActionPerformed

    //Buton Cu DAO
    private void addCuDAOActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addCuDAOActionPerformed
       PersoanaDAO pDao = new SwingPersoanaDAO(persoanaGUIImputCuDAO, persoanaGUIoutputCuDAO);
       ptDAOPersoana p = pDao.importPersoasa();
       /*
        * aici merge la fel ca la Builder in sensu ca pot sa am doua DAO-uri unu care ia din GUI, sa zice, si
        * altu care exporta la consola
        * vazi clasa  TutorialCombinat pentru detalii
        */
       pDao.exportPersoana(p);
    }//GEN-LAST:event_addCuDAOActionPerformed
   
    
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(TutorialCuGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(TutorialCuGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(TutorialCuGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(TutorialCuGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new TutorialCuGUI().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addCuBuilder;
    private javax.swing.JButton addCuDAO;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private tutorial.BuilderSiDAO.customGUI.PersoanaGUIInput persoanaGUIImputCuDAO;
    private tutorial.BuilderSiDAO.customGUI.PersoanaGUIInput persoanaGUIinputCuBuiller;
    private tutorial.BuilderSiDAO.customGUI.PersoanaGUIOutput persoanaGUIoutputCuBuilder;
    private tutorial.BuilderSiDAO.customGUI.PersoanaGUIOutput persoanaGUIoutputCuDAO;
    // End of variables declaration//GEN-END:variables
}
